home *** CD-ROM | disk | FTP | other *** search
- /***
- * URLHelperComponentStandard.c
- *
- * Routines to implement the target and register stuff for this component.
- *
- ***/
-
- #include "debug_me.h"
- #include "URLHelperComponent.h"
- #include "URLHelperComponentPrivate.h"
- #include "Exceptions.h"
-
- /**
- * _URLHelperOpen
- *
- * This guy is begin opened. Allocate the global storage we need to use.
- *
- **/
- pascal ComponentResult _URLHelperOpen (Handle storage, ComponentInstance theComp)
- {
- URLGlobalsHandle globalsHandle;
- URLGlobalsPtr globals;
- OSErr theErr;
-
- /**
- ** Try to allocate our globals. If we can't, then we are in some
- ** big time trouble and we need to bail out.
- **/
-
- globalsHandle = (URLGlobalsHandle) NewHandleClear (sizeof(URLGlobals));
- theErr = MemError ();
- require (globalsHandle != 0, FailedAllocateGlobals);
-
- /**
- ** Install the globals as our instance variables
- **/
-
- SetComponentInstanceStorage (theComp, (Handle) globalsHandle);
-
- /**
- ** To make the rest simple, lock the globals handle down and deref it
- **/
-
- HLock ((Handle) globalsHandle);
- globals = *globalsHandle;
-
- /**
- ** Remember who we are so that we can call ourselves in other routines.
- **/
-
- globals -> self = theComp;
- globals -> mirrorList = 0;
-
- /**
- ** Done! We can return no err now...
- **/
-
- HUnlock ((Handle) globalsHandle);
-
- return noErr;
-
- /**
- ** Handle all the errors that occured during setup
- **/
-
-
- FailedAllocateGlobals:
- return theErr;
- }
-
- /**
- * _URLHelperClose
- *
- * Close this instance down. Deallocate the instance storage...
- *
- **/
- pascal ComponentResult _URLHelperClose (Handle storage, ComponentInstance self)
- {
- URLGlobalsHandle globals = (URLGlobalsHandle) storage;
-
- /**
- ** Make sure the globals are non zero...
- **/
-
- if (globals != 0) {
- DisposHandle ((Handle) globals);
- SetComponentInstanceStorage (self, 0L);
- }
-
- return noErr;
- }
-
- /**
- * _URLHelperCanDo
- *
- * Return true if we can actually perform some function
- *
- **/
- pascal ComponentResult _URLHelperCanDo (short selector)
- {
- switch (selector) {
-
- // The component manager request codes
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentTargetSelect:
-
- // Our URLHelper component request codes
- case kDoGetMirrorList:
- case kDoNewMirrorList:
- case kDoAddMirror:
- case kDoNumberOfMirrors:
-
- return true;
- break;
-
- // All else, we can't do
- default:
- return false;
- }
- }
-
- /**
- * _URLHelperVersion
- *
- * Return the interface revision number
- *
- **/
- pascal ComponentResult _URLHelperVersion (void)
- {
- return URLHelperInterfaceRevision;
- }
-
- /**
- * _URLHelperTarget
- *
- * Someone is going to capture us for later use. Save the targeting compontent
- * for later internal use
- *
- **/
- pascal ComponentResult _URLHelperTarget (Handle storage, ComponentInstance capturingComponent)
- {
- URLGlobalsHandle globals = (URLGlobalsHandle) storage;
- OSErr theErr;
-
- /**
- ** Make sure all is ok
- **/
-
- theErr = paramErr;
- require (globals != 0 && capturingComponent != 0, BadParams);
- theErr = noErr;
-
- /**
- ** Ok -- save the component instance so we can use it to call our own routines
- **/
-
- (*globals) -> self = capturingComponent;
-
- BadParams:
- return theErr;
-
- }
-